const _ = require('lodash')

const array = ['jack', 'tom', 'lucy', 'kate']

// console.log(_.first(array))
// console.log(_.last(array))
// console.log(_.toUpper(array))

function getSum (a, b, c){
    return a + b + c
}

//模拟lodash的curry方法
function curry (fn){
    let parameterNum = fn.length //获取传入的函数定义了几个参数
    return function (){
        let arrayArguments = Array.prototype.slice.call(arguments)
        //console.log(arrayArguments)
        if(arrayArguments.length >= parameterNum){
            return fn.apply(fn, arrayArguments.slice(0,parameterNum))
        }else{
            return function (){
                return fn.apply(fn, arrayArguments.concat(Array.prototype.slice.call(arguments)))
            }
        }
    }
}

const curried = curry(getSum)

console.log(curried(1, 2, 3))
console.log(curried(1)(2, 3))
console.log(curried(1, 2)(3))
console.log(curried(1)(3, 3))